/*  This file is part of -_-.

    -_- is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    -_- is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with -_-.  If not, see <http://www.gnu.org/licenses/>.

    Copyright 2012-2013 Oliver Katz */

#ifndef __COMMON_TYPES_STRING_H
#define __COMMON_TYPES_STRING_H

#include "../data.h"

#define Z_WARNING_STRING(s, r) if((s)->content==NULL||(s)->size==0){Z_WARNING("cannot operate on null object: %s", #s);return r;}

typedef struct 
{
    char *content;
    unsigned int size;
} _z_string;

z_data z_string_new(); //method: create a new empty string
z_data *_z_string_new();
z_data z_string_new_from(char *s); //method: create a new string from 's'
z_data *_z_string_new_from(char *s);
int z_string_del(z_data *s); //method: delete a string
char z_string_at(z_data *s, int idx); //method: get the character at index 'idx'
int z_string_size(z_data *s); //method: get length of a string (in bytes)
int z_string_find_string(z_data *s, z_data *p); //method: find the first instance of the pattern 'p' in a string
int z_string_find_char(z_data *s, char c); //method: find the first instance of the character 'c' in a string
z_data z_string_substring(z_data *s, int idx0, int idx1); //method: get a substring from 'idx0' to 'idx1'
z_data *_z_string_substring(z_data *s, int idx0, int idx1);
char *z_string_safe(z_data *s); //method: get a safely-usable version of the string that's c-compatible (duplicates the memory space)

#endif